// 两个接口
// 一个是 request 后缀是 api 的请求使用 request
// 一个是 serve 后缀是 ips 的请求使用 reque

import request from '@/utils/request'
// import serve from '@/utils/serve'

// 查询分页货品 + 查询(精确查询)
export const getGoodsPage = (pageConfig, searchQuery) => {
  const params = { ...pageConfig }
  if (searchQuery) {
    const [code, name, ownerName] = searchQuery
    if (code) params.code = code
    if (name) params.name = name
    if (ownerName) params.ownerName = ownerName
  }
  return request.get('/goods/pageDetail', { params })
}

// 删除货品
export const delGoods = (id) => request.delete('goods', { params: { ids: [id] }})

// 新增货品时获取货品编码
export const getGoodCode = () => request.get('/codeFactory/next/HP')

// 查询货品类型
export const getGoodsType = () => request.get('/goodsType/list')

// 查询货主
export const getOwnerList = () => request.get('/owner/list')

// 查询库区 /area/list
export const getWarehouseArea = (id) => request.get(`/area/list?ownerId=${id}`)

// 新增货品
export const addGoods = (data) => request.post('/goods', data)

// 根据id查询货品详情
export const getGoodsDetails = (id) => request.get(`/goods/${id}`)

// 编辑货品
export const editGoods = (data) => request.put('/goods', data)
